package models.wiki;

import net.sf.oval.constraint.MaxLength;
import play.db.jpa.Model;
import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.Column;
import javax.persistence.OneToMany;

import com.petebevin.markdown.MarkdownProcessor;

/**
 * @author Valentin.Kononov
 *
 * Class represents wiki page entity
 */

@Entity
public class Page extends Model {

    private static MarkdownProcessor markDownProcessor = new MarkdownProcessor();

    public String name;

    @Column(columnDefinition = "TEXT")
    public String content;

    public String summary;

    public Date createdDate;
    public Date lastEditedDate;
    public String last_modifier_id;
    public String author_id;

    //@OneToMany
    public String[] tags;

    public String contentHtml(){
        return markDownProcessor.markdown(content);
    }

    public String summaryHtml(){
        return markDownProcessor.markdown(summary);
    }

    public String getTagsString(){
        String result = "";
        if(tags != null) {
            for(int i = 0;i<tags.length;i++){
                result += tags[i];
                if(i < tags.length - 1){
                    result += ", ";
                }
            }
        }
        return result;
    }

    public String getHtmlContent(MarkdownProcessor markProcessor, String content){
        return markProcessor.markdown(content);
    }
}
